#include "mainscene.h"
#include "ui_mainscene.h"
#include<QPainter>
#include<QObject>
#include "mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include <QSound>
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    setFixedSize(320,588);
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    setWindowTitle("翻金币");

    //退出按钮实现
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });
    //准备开始音效
    QSound *startSound=new QSound(":/res/TapButtonSound.wav",this);
//    startSound->setLoops(-1);//设置循环，如果是-1代表无限循环
//    startSound->play();
    //开始按钮实现
    MyPushButton *startbtn=new MyPushButton(":/res/MenuSceneStartButton.png");
    startbtn->setParent(this);
    startbtn->move(this->width()*0.5-startbtn->width()*0.5,this->height()*0.7);

    //实例化选择关卡场景
     chooseScene=new ChooseLevelScene;

     //监听选择关卡的返回按钮信号
     connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
         this->setGeometry(chooseScene->geometry());
         chooseScene->hide();//将选择关卡场景隐藏
         this->show();//重新显示主场景

     });
    connect(startbtn,&MyPushButton::clicked,[=](){

        qDebug()<<"点击了";
        //播放开始音效资源
        startSound->play();
        //做弹起特效
        startbtn->zoom1();
        startbtn->zoom2();
        //延时进入关卡选择场景
        QTimer::singleShot(500,this,[=](){
            chooseScene->setGeometry(this->geometry());
            this->hide();
            chooseScene->show();
        });
    });


}

 void  MainScene:: paintEvent(QPaintEvent *)
 {
     QPainter painter(this);
     QPixmap pix;
     pix.load(":/res/PlayLevelSceneBg.png");
     painter.drawPixmap(0,0,this->width(),this->height(),pix);
     //画背景图标
     pix.load(":/res/Title.png");
     pix=pix.scaled(pix.width()*0.5,pix.height()*0.5);
     painter.drawPixmap(10,30,pix);

 }
MainScene::~MainScene()
{
    delete ui;
}


